﻿#define _CRT_SECURE_NO_WARNINGS 1
//只出现一次的数字 |||（medium）:https://leetcode.cn/problems/single-number-iii/
class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        unsigned int ret = 0;
        for (auto x : nums)
        {
            ret ^= x;
        }

        vector<int> v(2);
        ret &= (-ret);
        for (auto x : nums)
        {
            v[(ret & x) != 0] ^= x;
        }
        return v;
    }
};

//判断字符是否唯⼀（easy）:https://leetcode.cn/problems/is-unique-lcci/
class Solution {
public:
    bool isUnique(string astr) {
        int n = astr.size();
        if (n > 26)  return false;

        int bitMap = 0;
        for (auto ch : astr)
        {
            int i = ch - 'a';
            if ((bitMap >> i) & 1)
            {
                return false;
            }
            bitMap |= 1 << i;
        }
        return true;
    }
};

//丢失的数字（easy）:https://leetcode.cn/problems/missing-number/submissions/571940889/
class Solution {
public:
    int missingNumber(vector<int>& nums) {
        int n = nums.size();
        int ret = 0;
        for (auto x : nums)
        {
            ret ^= x;
        }
        for (int i = 0; i <= nums.size(); i++)
        {
            ret ^= i;
        }
        return ret;
    }
};